/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ainlolcat.aincalc;

import org.ainlolcat.ainscience.entity.Entity;

import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;

/**
 *
 * @author Администратор
 */
public class Cleks {
    ArrayList command;
    ArrayList constants;
    ArrayList outcom;
    Dictionary<String,String> outvarval;
    Dictionary<String,String> outvartype;
    Entity entity;

    public Cleks(Entity entity){
        this.entity = entity;
        init();
    }

    private void init(){
        initCommands();
        initVariables();
    }

    private void initVariables(){
        constants = new ArrayList();
        outvarval = new Hashtable();
        outvartype = new Hashtable();

        constants.add("pi");
    }

    private void initCommands(){
        command = new ArrayList();
        outcom = new ArrayList();

        command.add("val");
        command.add("abs");
        command.add("sqrt");
        command.add("min");
        command.add("max");
        command.add("round");
        command.add("pow");
        command.add("sin");
        command.add("cos");
        command.add("tan");
    }

    public boolean iscommand(String input)        {
        if (command.indexOf(input) != -1) return true;
            else return false;
    }

    public boolean isconstant(String input)        {
        if (constants.indexOf(input) != -1) return true;
            else return false;
    }

    public String getConstValue(String input)        {
        if (input.compareTo("pi") == 0) return Double.valueOf(java.lang.Math.PI).toString();
            else return null;
    }

    public void setcom(String name){
        if (command.indexOf(name)!=-1) command.remove(name);
            outcom.add(name);
    }

    public void addvar(String name, String val, String type){
        outvarval.put(name, val);
        outvartype.put(name, type);
    }

    public void updvar(String name, String val){
        outvarval.remove(name);
        outvarval.put(name, val);
    }

    public String getvar(String name) {
        return outvarval.get(name);
    }

    public String getvartype(String name) {
        return outvartype.get(name);
    }

    public boolean isOutVar(String name){
        return (outvarval.get(name)!=null);
    }

    public boolean isOutCom(String name){
        if (outcom.indexOf(name) != -1) return true;
            else return false;
    }
}
